{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Making entry auto form"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Make a form having fields 'First Name', 'Last Name', 'Country', 'State', 'City', 'Mobile Number'; which will take data from user. Add two button to show user entred data and quite form. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from tkinter import *\n",
    "\n",
    "fields = 'First Name', 'Last Name', 'Country', 'State', 'City', 'Mobile Number'\n",
    "\n",
    "\n",
    "def fetch(entries):\n",
    "    for entry in entries:\n",
    "        field = entry[0]\n",
    "        text = entry[1].get()\n",
    "        print(\"%s:%s\"%(field, text))\n",
    "\n",
    "def makeform(root, fields):\n",
    "    entries = []\n",
    "    for field in fields:\n",
    "        row = Frame(root)\n",
    "        lab = Label(row, width=15, text=field, anchor='w')\n",
    "        ent = Entry(row)\n",
    "        row.pack(side=TOP, fill=X, padx=5, pady=5)\n",
    "        lab.pack(side=LEFT)\n",
    "        ent.pack(side=RIGHT, expand=YES, fill=X)\n",
    "        entries.append((field, ent))\n",
    "    return entries\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    root = Tk()\n",
    "    ents = makeform(root, fields)\n",
    "    \n",
    "    b_show = Button(root,\n",
    "                   text='Show',\n",
    "                   command=(lambda e=ents: fetch(ents))\n",
    "                   )\n",
    "    b_stop = Button(root,\n",
    "                   text='Quite',\n",
    "                   command=root.destroy)\n",
    "\n",
    "    b_show.pack(side=LEFT, padx=5, pady=5)\n",
    "    b_stop.pack(side=LEFT, padx=5, pady=5)\n",
    "\n",
    "    root.mainloop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
